<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="../common/meta.jsp"%>
<%@ include file="../common/taglibs.jsp"%>
<link rel="stylesheet" type="text/css"
	href="<%=request.getContextPath()%>/easyui/themes/myself/easyui.css" />
<link rel="stylesheet" type="text/css"
	href="<%=request.getContextPath()%>/easyui/themes/icon.css" />
<script type="text/javascript"
	src='<%=request.getContextPath()%>/dwr/engine.js'></script>
<script type="text/javascript"
	src='<%=request.getContextPath()%>/dwr/util.js'></script>
<script type="text/javascript"
	src='<%=request.getContextPath()%>/dwr/interface/baseVerifyService.js'></script>
<style>
.btn {
	BORDER-RIGHT: 0px;
	BORDER-TOP: 0px;
	BACKGROUND: url(<%=request.getContextPath()%>/images/bg_rectbtn.png) -2px -2px repeat-x;
	OVERFLOW: hidden;
	BORDER: solid 1px #83858C;
}
* {
	margin: 0;
	padding: 0;
	font-size: 12px;
}
</style>
<script type="text/javascript">
	function addSubDept() {
		var bform = document.getElementById("ctDeptForm");
		bform.action = "edit.action?operate=insertSub";
		bform.target = "_self";
		bform.submit();
	}
	function deleteDept(deptId) {
		baseVerifyService.isDeptRefByStaff(deptId, {callback:function(data) {
            showVerify(data, deptId);
        }});
	}
	function showVerify(data, deptId) {
		if (data != null && data != "") {
			parent.$.messager.alert("消息","此部门或者其子部门已被用户"+data+"关联，不允许删除！","info");
            return false;
		} else if (confirm("确认删除此部门？")) {
			$("#ctDeptForm").form("submit",{
				url: "delete.action?deptId=" + deptId,		
				success: function(data) {
					parent.$.messager.progress('close');
					parent.$.messager.alert('消息','删除成功!','info');
					var node = parent.$("#deptTree").tree("getSelected");
					var parentNode = parent.$("#deptTree").tree('getParent',node.target);
					parent.$("#deptTree").tree('reload',parentNode.target);
					parent.$("#deptTree").tree('select',parentNode.target);
				}
			});
		}
	}
	function saveDept() {
		parent.$.messager.progress();
		$("#ctDeptForm").form("submit",{
			url: "save.action?operate=${operate}",			
			onSubmit: function() {
				var menuNameObj = this['deptName'];
				if (menuNameObj.value == "") {
					parent.$.messager.alert("消息","请输入部门名称！","info");
					parent.$.messager.progress('close');
					menuNameObj.focus();
					return false;
				}
			},
			success: function(data) {
				parent.$.messager.progress('close');
				parent.$.messager.alert('消息','保存成功!','info');
				var node = parent.$("#deptTree").tree("getSelected");
				if('${operate}' == 'insertSub') {
					parent.$("#deptTree").tree('reload',node.target);
					parent.$("#deptTree").tree('select',node.target);
				} else if('${operate}' == 'editView') {
					var parentNode = parent.$("#deptTree").tree('getParent',node.target);
					parent.$("#deptTree").tree('reload',parentNode.target);
					parent.$("#deptTree").tree('select',parentNode.target);
				}
			}
		});
	}
</script>
</head>
<body>
	<div class="easyui-layout" data-options="fit:true">
	<form id="ctDeptForm" method="post">
		<input type="hidden" id="deptId" name="department.deptId" value="${department.deptId}"/>
		<input type="hidden" id="parentId" name="department.parentId" value="${department.parentId}"/>
		<div data-options="region:'north', border:false" id="msgDiv">
		</div>
		<div data-options="region:'center', border:false">
			<div class="easyui-layout" data-options="fit:true">
				<div data-options="region:'center', border:false"
					style="border: 1px solid #ccc;padding: 5px;">
						
						<table border="0" align="center" cellpadding="3" cellspacing="1" class="tb_input">
            <tr><td colspan="2" height="30px">
                 <s:if test="#request.operate eq 'editView'">
                    <input type="button" value="创建子部门" class="button_std" onclick="addSubDept()"/>
                    &nbsp;
                    <input type="button" value="删除此部门" class="button_std" onclick="deleteDept('${department.deptId}')"/>
                 </s:if>
                 <s:else>创建部门</s:else>
                </td>
            </tr>
            <tr>
                <td class="td_title" nowrap="nowrap" width="200px">部门名称<font color="#FF0000">*</font></td>
                <td><input type="text" id="deptName" name="department.deptName" value="${department.deptName}" style="WIDTH: 250px"/></td>
            </tr>
            <tr>
                <td class="td_title" nowrap="nowrap" width="200px">部门联系人</td>
                <td><input type="text" id="deptContact" name="department.deptContact" value="${department.deptContact}" style="WIDTH: 250px"/></td>
            </tr>
            <tr>
                <td class="td_title" nowrap="nowrap" width="200px">部门联系电话</td>
                <td><input type="text" id="deptPhone" name="department.deptPhone" value="${department.deptPhone}" style="WIDTH: 250px"/></td>
            </tr>
            <tr>
                <td class="td_title" nowrap="nowrap" width="200px">部门联系地址</td>
                <td>
                  <textarea id="deptAddr" name="department.deptAddr" rows="2" cols="45">${department.deptAddr}</textarea>
                </td>
            </tr>
            <tr>
                <td class="td_title" nowrap="nowrap" width="200px">说明</td>
                <td>
                  <textarea id="memo" name="department.memo" rows="3" cols="45">${department.memo}</textarea>
                </td>
            </tr>
        </table>
        <br />
        <table border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
                <td align="center">
                    <input type="button" value="保存" class="button_std" onclick="saveDept();"/>
                </td>
            </tr>
        </table>
				</div>
			</div>
		</div>
	</form>
	</div>
</body>
</html>